package org.dejavu.util;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import org.dejavu.cte.Pinyin;

public class PropertiesUtil {

	public static String readeFile(String filePath) {
		StringBuffer line = new StringBuffer();
		try {
//			String filePath="res/aa.txt";
			String encoding = "utf-8";

			File file = new File(filePath);

			if (file.isFile() && file.exists()) { // 判断文件是否存在

				InputStreamReader read = new InputStreamReader(

				new FileInputStream(file), encoding);// 考虑到编码格式

				BufferedReader bufferedReader = new BufferedReader(read);

				String lineTxt = null;
				Pinyin pinyin = new Pinyin();
				while ((lineTxt = bufferedReader.readLine()) != null) {

					System.out.println(pinyin.HanyuToPinyin(lineTxt));
					System.out.println(lineTxt);
					line.append(lineTxt);

				}

				read.close();

			} else {

				System.out.println("找不到指定的文件");

			}

		} catch (Exception e) {

			System.out.println("读取文件内容出错");

			e.printStackTrace();

		}
		return line.toString();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		String filePath="res/道德经.txt";
//		String filePath="res/千字文.txt";
//		String filePath="res/三字经.txt";
		String filePath="res/增广贤文.txt";
//		String readeFile = PropertiesUtil.readeFile(filePath);
//		System.out.println(readeFile);
		//要操作的字符串 
		getZF("打算离开房间爱圣诞快乐； 发生点开了房间爱乐山大佛拉屎都开了房间爱上的离开");
	}
	
	public static void getZF(String str){
//		String[] split = str.split(str);
		char[] charArray = str.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			System.out.println(charArray[i]);
			int count = 0 ;
			for (int j = 0; j < charArray.length; j++) {
				if (charArray[i]==charArray[j]) {
					count++;
				}
			}
			System.out.println(charArray[i] + " 有 " + count + " 个 ");
		}
	}

}
